/*
 *  MTouchware_touch.h
 *
 *  data structures used in MTouchWare for TUIO filtering.
 *
 *  Copyright (C) 2010 LIMSI-CNRS (Orsay-France) and EFREI (Paris-France)
 *
 *  Authors: Rami Ajaj, Nicolas Flasque and Frederic Vernier.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation; either version 2.1 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  $Id$
 */
#ifndef _MTOUCHWARE_TOUCH_H_
#define _MTOUCHWARE_TOUCH_H_

#include "lo/lo.h"

#define MT_NB_FORMATS   10
#define MAX_NB_TOUCHES 	32
#define INPUT_TAB_SIZE  10

// TUIO contact type used to know which fields to store & process
typedef enum
{
    TUIO_2D_OBJ,
    TUIO_25D_OBJ,
    TUIO_3D_OBJ,
    TUIO_2D_BLB,
    TUIO_25D_BLB,
    TUIO_3D_BLB,
    TUIO_2D_CUR,
    TUIO_25D_CUR,
    TUIO_3D_CUR,
    TUIO_CUSTOM_FORMAT
} t_tuio_format;

t_tuio_format get_tuio_format_from_string(const char *);
char *get_path_string(t_tuio_format);

// simple structure to store values incoming from OSC bundles
typedef struct
{
    long    session_id;
    long    object_id;

    struct
    {
            float   x,y,z;
    } where;

    struct
    {
            float   a,b,c;
    } angle;

    struct
    {
            float   w, h, d;
    } dims;

    struct
    {
            float   sx, sy, sz;
    } speed;

    struct
    {
            float   rvx, rvy, rvz;
    } rotationVelocity;

    float   area;
    float   volume;

    float   motionAccel;
    float   rotationAccel;

} t_touch_values, *p_touch_values;

void initValues(p_touch_values);
void displayValues(p_touch_values);

///< structure to store touch status wrt current bundle,
///< raw touch values and pointer to previous info on this touch for
///< handling history

typedef struct s_touch_info
{

    enum
    {
        ADDED_NOW,                 ///< touch appears in current bundle (check alive list)
        UPDATED_NOW,               ///< touch is updated in current bundle
        REMOVED_NOW,               ///< touch is removed in current bundle (check alive list)
        NOT_IN_CURRENT_BUNDLE,      ///< no info on an existing touch (marked as alive but not set)
    }                   input_status;

    enum
    {
        SEND,
        DONT_SEND
    }                   output_status;

    p_touch_values      pvalues;             ///< pointer to current values, may reference old touch_info if NOT_IN_CURRENT_BUNDLE
    struct s_touch_info *prev;              ///< pointer to previous status

} t_touch_info, *p_touch_info;


///< structure to handle a set of touches for a given time
///< corresponding to an incoming OSC bundle
typedef struct
{
        float           time;
        long		    alivelist[MAX_NB_TOUCHES];
        long            nbTouchInfo;
        p_touch_info    touchInfoTab;
} t_touches, *p_touches;

///< structure to handle several sets of touches (memory of previous touches)
typedef struct
{
    t_touches   touchdata[INPUT_TAB_SIZE];
    long        currentIndex;
    long        first;          ///< first value stored in array indicates if previous data is available
} t_tab_touches;


#endif // _MTOUCHWARE_TOUCH_H_
